//
//  MSRequestObject.h
//  Musou
//
//  Created by danal on 13-3-18.
//
//

#import <Foundation/Foundation.h>
#import "MSHTTPRequest.h"

@class MSHTTPRequest;
@protocol MSRequestObjectDelegate;

@interface MSRequestObject : NSObject <MSHTTPRequestDelegate>
@property (copy, nonatomic) NSString *url;
@property (nonatomic) BOOL post;
@property (strong, nonatomic) NSMutableDictionary *requestParams;
@property (assign, nonatomic) id<MSRequestObjectDelegate> delegate;
@property (assign, nonatomic) id requestSender;
@property (copy, nonatomic) void (^completeBlock)(MSRequestObject *, NSError *, id);

- (id)initWithUrl:(NSString *)url;

//If you want to custom fill post parametes, override this method
- (void)prepare;

//Set request parameter
//Post
- (void)setValue:(id)value forField:(NSString *)field;
//Get
- (void)setGetValue:(id)value forField:(NSString *)field;

//Using Delegate, return an integer value to identify itself
- (void)startGetWithDelegate:(id<MSRequestObjectDelegate>)delegate;
- (void)startPostWithDelegate:(id<MSRequestObjectDelegate>)delegate;

//Using Block
//the object is  a optional directly pass-in parameter for accessing in the block so it would not be retained
- (void)startGetWithBlock:(void(^)(id requestObject, NSError *error, id object))block sender:(id)object;
- (void)startPostWithBlock:(void(^)(id requestObject, NSError *error, id object))block sender:(id)object;

- (void)start;

//Cancel
- (void)cancel;

//Override this method to parse the result data
- (void)parse:(id)result;

@end


@protocol MSRequestObjectDelegate <NSObject>
@optional
- (void)onRequestStart:(MSRequestObject *)rqo;
- (void)onRequestComplete:(MSRequestObject *)rqo error:(NSError *)error;

@end
